<?php
/**
 * 《客户信息》实现类
 *
 * @author 孙晓晔
 * @version $Id: Work.class.php 1035 2010-03-26 05:24:59Z sunxy $
 */
require_once(dirname(__FILE__) . '/Customer.class.php');

class FinanceCustomer extends Customer {

	function __construct() {
		$request['update'] = '$Date: 2009/02/16 07:36:07 $';
		$request['revision'] = '$Revision: 1.1 $';

		parent::__construct();
	}

	function find($controller, $request) {
		$this->pretreat($controller);

		$controller->display($request, 'contact/customer/finance/find');
		return true;
	}
	
	function findPost($controller, $request) {
		$this->pretreat($controller);

		$this->findPara($controller, $request);

		$db = newdb($this->dsn_r);
		$fmt = "SELECT * FROM %s a %s %s";
		$where = $this->_where($request);
		$orderby = $this->_orderby();		
		$sql = sprintf($fmt, $this->tbl, $where, $orderby);
		debug($sql);

		$pager_option = array (
            'db' => $db,
            'sql' => $sql,
            'PageSize' => $this->pagesize,
            'CurrentPageID' => $request['p'],
            'numItems' => $request['n']
		);

		$pager = @new Pager($pager_option);
		$data = $pager->getPageData();

		if ($pager->number > 0) {

			$count = 0;
			$from = $pager->from;
			while ($count < $pager->number) {
				$row = $data[$count];
				$row = $this->_view(null, $row);

				$row['c'] = $this->_contact1($this->info, $row['id']);

				$country = $this->code(Constant::tbl_country, $row['country']);
				if ($country) {
					$row['country_t'] = $country['name'] . '[' . $country['zone'] . ']';
				}

				$row = $this->_orderby_x($controller, $row, $this->orderby_s);

				$data[$count] = $row;
				$count++;
			}
			$controller->assign_by_ref('result', $data);
			$controller->assign_by_ref('pager', $pager);
		}

		$controller->display($request, 'contact/customer/finance/list');
		return true;
	}
	
	function view($controller, $request) {
		$this->pretreat($controller);

		$id = $request['id'];
		$row = $this->_view($id);
		
		$country = $this->code(Constant::tbl_country, $row['country']);
		if ($country) {
			$row['country_t'] = $country['name'] . '[' . $country['zone'] . ']';
		}

		$controller->assign_by_ref('result', $row);

		$controller->display($request, 'contact/customer/finance/view');
		return true;
	}
}
?>